#include <iostream>
#include <vector>
#include <sstream>
using namespace std;


class CItem
{
public:
	CItem(int n = 0) : number(n){}

	void print()
	{
		cout<<"Number: "<<number<<endl;
	}

	int number; 
};


class c1
{
public:
	c1()
	{
		for (int i = 0; i < 20; ++i)
		{
			data.push_back(i);
		}
	}
	bool GetItem(int value, CItem* p)
	{
		if ( NULL == p)
		{
			return false;
		}

		std::vector<CItem>::iterator it = data.begin();

		while ( it != data.end() )
		{
			if ( it->number == value)
			{
				*p = *it;
				break;
			}
			++it;
		}

		if ( it != data.end())
			return true;
		else
			return false;
	}
	bool show(){cout<<"C1 class"<<endl; return true;}
private:
	std::vector<CItem> data;
};


class c2
{
public:
	bool display(){cout<<"C2 class"<<endl; return true;}
};

template<typename StoryName, typename FuncName>
bool function_bool_void(StoryName* pStory, FuncName func, char** kv, int num)
{
	typedef bool (StoryName::*classFunc)(void);
	classFunc pFunc = reinterpret_cast<classFunc>(func);
	(pStory->*pFunc)();
	return true;
}

template<typename StoryName, typename ItemName, typename FuncName>
bool function_bool_int_item(StoryName* pStory, ItemName* , FuncName func, int key,  char** kv, int num)
{
	typedef bool (StoryName::*classFunc)(int, ItemName*);

	ItemName item;

	classFunc pFunc = reinterpret_cast<classFunc>(func);
	bool ret = (pStory->*pFunc)(key, &item);
	
	if (ret)
	{
		std::stringstream str;
		str<<"number:"<<item.number<<" ";
		for (int i=0; i<2; ++i)
		{
			str<<"["<<*(kv+i)<<"]"<<" ";
		}
		cout<<str.str()<<endl;
	}

	return ret;
}

void main()
{
	c1* pc1 = new c1;
	function_bool_void(pc1, &c1::show, NULL, 0);

	char *p[2];
	p[0] = "hello";
	p[1] = "world";
	function_bool_int_item(pc1, (CItem*)0, &c1::GetItem, 10, p, 2);

	delete pc1;
}
